package com.chenzp.rocketmq.simple;

import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.common.message.Message;

import java.nio.charset.StandardCharsets;

/**
 * @Classname OnewayProducer
 * @Description 单向消息  不需要返回值
 * @Version 1.0.0
 * @Date 2025-06-12 17:32
 * @Created by ncs
 */
@Slf4j
public class OnewayProducer {

    @SneakyThrows
    public static void main(String[] args) {
        DefaultMQProducer defaultMQProducer = new DefaultMQProducer("my-group-producer");
        defaultMQProducer.setNamesrvAddr("192.168.125.102:9876");
        defaultMQProducer.start();
        for (int i = 0; i < 100; i++) {
            Message message = new Message("myTopic1", "TagA", ("第"+i+"条消息").getBytes(StandardCharsets.UTF_8));
            defaultMQProducer.sendOneway(message   );
        }
    }
}
